(function() {
    'use strict';

    angular
        .module('logcenterApp')
        .controller('NavbarController', NavbarController);

    NavbarController.$inject = ['$state', '$scope','Auth', 'Principal', 'ProfileService', 'LoginService','ACTIVE', "navbarTitle",'isMulti'];

    function NavbarController ($state, $scope,Auth, Principal, ProfileService, LoginService,active, navbarTitle,isMulti) {

         $scope.isShowNav =isMulti;
        $scope.icon = "content/images/logo-"+active+".png";

        active == 'run' ? $scope.show = true : $scope.show = false;
        switch(active){
            case "dev":
                $scope.dev = true;
                $scope.test = false;
                $scope.run = false;
                break;
            case "test":
                $scope.dev = false;
                $scope.test = true;
                $scope.run = false;
                break;
            case "run":
                $scope.dev = false;
                $scope.test = false;
                $scope.run = true;
                break;
            default:break;
        }

        var vm = this;


        vm.navbarTitle = navbarTitle;

        vm.isNavbarCollapsed = true;
        vm.isAuthenticated = Principal.isAuthenticated;

        ProfileService.getProfileInfo().then(function(response) {
            vm.inProduction = response.inProduction;
            vm.swaggerEnabled = response.swaggerEnabled;
        });

        vm.login = login;
        vm.logout = logout;
        vm.toggleNavbar = toggleNavbar;
        vm.collapseNavbar = collapseNavbar;
        vm.$state = $state;

        function login() {
            collapseNavbar();
            LoginService.open();
        }

        function logout() {
            collapseNavbar();
            Auth.logout();
            $state.go('home');
        }

        function toggleNavbar() {
            vm.isNavbarCollapsed = !vm.isNavbarCollapsed;
        }

        function collapseNavbar() {
            vm.isNavbarCollapsed = true;
        }
    }
})();
